import Mock from "mockjs";
export default {
  getData: config => {
    const payload = JSON.parse(config.body);
    const recordsTotal = 28; // 总记录条数
    const pageNo = parseInt(payload.pageNo); // 当前页
    const pageSize = parseInt(payload.pageSize); // 每页的条数
    const total = Math.ceil(recordsTotal / pageSize);
    const data = {};
    data.data = {
      treeData: [],
      pageNum: 1,
      pageSize: pageSize,
      size: 30,
      startRow: 1,
      endRow: 30,
      total: total,
      pages: 4,
      prePage: 0,
      nextPage: 2,
      isFirstPage: true,
      isLastPage: false,
      hasPreviousPage: false,
      hasNextPage: true,
      navigatePages: 8,
      navigatepageNums: [1, 2, 3, 4, 5, 6, 7, 8],
      navigateFirstPage: 1,
      navigateLastPage: 8,
      rows: []
    };
    let obj = {};
    if (payload.sortord === "descending" || payload.sortord === "ascending") {
      obj = Mock.mock({
        [`rows|${pageSize}`]: [
          {
            "demoId|+1": 1,
            "userName|1": "@cname()",
            "sex|1": '@pick(["0", "1", "2"])',
            birthday: "@date('yyyy-MM-dd')",
            "politicalOutlook|1": '@pick(["0", "1", "2"])',
            "workyears|1-20": 20,
            "isMarried|1": '@pick(["0", "1"])',
            "annualIcome|10000-20000": 20000,
            idNum: "@id()",
            userMobile: /^1[3-8]{10}$/,
            "modifyUserId|1-99": 99,
            remarks: "@cparagraph()"
          }
        ]
      });
    } else {
      obj = Mock.mock({
        [`rows|${pageSize}`]: [
          {
            "demoId|+1": 1,
            "userName|1": "@cname()",
            "sex|1": '@pick(["0", "1", "2"])',
            birthday: "@date('yyyy-MM-dd')",
            "politicalOutlook|1": '@pick(["0", "1", "2"])',
            "workyears|1-20": 20,
            "isMarried|1": '@pick(["0", "1"])',
            "annualIcome|10000-20000": 20000,
            idNum: "@id()",
            userMobile: /^1[3-8]{10}$/,
            "modifyUserId|1-99": 99,
            remarks: "@cparagraph()"
          }
        ]
      });
    }

    data.data.rows = obj.rows;
    data.data.pageNo = pageNo;
    data.data.recordsTotal = recordsTotal;
    data.code = "0";
    data.msg = "成功";
    data.attributes = "";
    data.errorDetail = "";
    return data;
  }
};
